package com.association.controller;

import com.alibaba.fastjson.JSON;
import com.association.constant.CodeEnum;
import com.association.model.ResultResp;
import com.association.model.entity.Dept;
import com.association.model.entity.User;
import com.association.service.DeptService;
import com.len.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 18244
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    DeptService deptService;

    /**
     * @explain 获取匹配用户
     * @param   对象参数：user
     * @return  List<User>
     * @author  xxy
     * @time    2019年4月9日
     */
    @ApiOperation(value = "条件查询用户", notes = "条件查询[user],作者：xxy")
    @RequestMapping(value="/list", method= RequestMethod.POST)
    public ResultResp list(){
        try {
            List<Dept> list = deptService.getList();
            return new ResultResp(list);
        } catch (Exception e) {
            logger.error("\"action\": \"deptList\", \"exception\": {}", e.getMessage());
            return new ResultResp(CodeEnum.SERVER);
        }
    }


    public static void main(String[] args) {
        int [] list = new int[]{1,5,3,4,2};
        for (int i= 1;i<list.length;i++){
            if (list[i]>=list[i-1]){
                continue;
            }
            int y = list[i];
            for (int z=i-1;z>=0;z--){
                if (y<list[z]){
                    int q = list[i];
                    list[i]=list[z];
                    list[z]=q;
                }
            }
        }
        for (int i : list) {
            System.out.println(i);
        }
    }
}
